$.fn.signup = function  () {

}
(function($){
$.fn.signup = function  () {
};

})(jQuery);

(function($) {

    // The validation function.
    // We adds validation rules for email, required field, password and url.
    var Validation = function() {

        var rules = {

            email: {
                check: function(value) {

                    if (value)
                        return isValidatedPattern(value, /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/);
                    return true;
                },
                msg: "Please enter a valid e-mail address."
            },
             phone: {
                check: function(value) {

                    if (value)
                       return isValidatedPattern(value,/^((0?1[358]\d{9})|((0(10|2[1-3]|[3-9]\d{2}))?[1-9]\d{6,7}))$/;);
                    return true;
                },
                msg: "phone rule"
            },
            url: {
                check: function(value) {

                    if (value)
                        return isValidatedPattern(value, /^https?:\/\/(.+\.)+.{2,4}(\/.*)?$/);
                    return true;
                },
                msg: "Please enter a valid URL."
            },
            password: {
                check: function(value) {
                    if (value.length < 8 || value.length > 20) {
                        return false;
                    }
                    else {
                        // Check the password strength enough.
                        return isValidatedPattern(value, /(?=[A-Za-z0-9]{8,20})(?=.*[A-Za-z])(?=.*[0-9])[A-Za-z0-9]+/);
                    }
                },
                msg: "Your password must be at least 8 characters long."
            },
            required: {
                check: function(value) {

                    if (value)
                        return true;
                    else
                        return false;
                },
                msg: "This field is required."
            }
        }
        var isValidatedPattern = function(value, pattern) {
            var regex = pattern;
            var match = regex.exec(value);
            return match;
        }

        // Returns a publish method, then the user can custom validation rule.
        return {

            addRule: function(name, rule) {

                rules[name] = rule;
            },
            getRule: function(name) {

                return rules[name];
            }
        }
    }

    //Creates instance of our object in the jQuery namespace.
    $.Validation = new Validation();
})(jQuery);
// We're passing jQuery into the function
// so we can use $ without potential conflicts.


// Adds custom rule.
/*$.validation.addRule("phoneRule", {
    check: function(value) {
      
                        return isValidatedPattern(value,/^((0?1[358]\d{9})|((0(10|2[1-3]|[3-9]\d{2}))?[1-9]\d{6,7}))$/;);
    },
    msg: "Must equal to the word JK_Rush."
});*/

//接下来，我们定义一个Form类型，它表示DOM中的表单实例。

// The Form type.
var Form = function(form) {

    var fields = [];

    // Find the field has the validation attribute.
    form.find("[validation]").each(function() {
        var field = $(this);
        if (field.attr('validation') !== undefined) {
            fields.push(new Field(field));
        }
    });
    this.fields = fields;
}

// The Field type.
var Field = function(field) {

    this.field = field;
    this.valid = false;
    //this.attach("change");
}

